package com.aiatomic.couting.settings;

import com.aiatomic.couting.R;
import com.aiatomic.couting.SettingActivity;

import android.app.Fragment;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class FragmentGeneralSettings extends Fragment {
	private View view;

	private SettingActivity activity;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.fragment_general_settings, container, false);
		activity = (SettingActivity) this.getActivity();
		TextView txtBack = (TextView) activity.findViewById(R.id.txtBack);
		txtBack.setText(R.string.bottom_setup);
		txtBack.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activity.onBackPressed();
			}
		});
		TextView txtNext = (TextView) activity.findViewById(R.id.txtNext);
		txtNext.setVisibility(View.INVISIBLE);

		TextView txtMiddle = (TextView) activity.findViewById(R.id.txtMiddle);
		txtMiddle.setText(R.string.general_settings);
		bindEvent();
		return view;
	}

	private void bindEvent() {
		SharedPreferences shared = activity.getSharedPreferences("setting", activity.MODE_PRIVATE);
		((SeekBar) view.findViewById(R.id.seekBar))
				.setProgress((int) (shared.getFloat("tag_size_scale", 1.0f) * 100) - 50);
		((SeekBar) view.findViewById(R.id.seekBar)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
					SharedPreferences.Editor editor = activity.getSharedPreferences("setting", activity.MODE_PRIVATE)
							.edit();
					editor.putFloat("tag_size_scale", (seekBar.getProgress() + 50) / 100.0f);
					editor.commit();
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
			
			}
		});
		view.findViewById(R.id.txt_chooseTagColor).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FragmentChooseTagColor fragment=new FragmentChooseTagColor();
				activity.addFragment(fragment);
			}
		});
	}

}
